﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Core
{
    public delegate SchoolClass GetData();

    /// <summary>
    /// Пункт меню для плагина
    /// </summary>
    public partial class PlugItem : ToolStripMenuItem
    {
        public PlugItem()
        {
            InitializeComponent();
        }

        public PlugItem(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        /// <summary>
        /// Экземпляр плагина
        /// </summary>
        public _BasePlugin plugin = null;

        public GetData getclass = null;

        public Form owner = null;

        private SchoolClass value = null;

        private void PlugItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (getclass != null && owner != null && plugin != null)
                {
                   
                    value = getclass();
                    Thread exec = new Thread(new ThreadStart(Run));
                    exec.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка использования плагина.");
            }
        }

        private void Run()
        {
            plugin.MainMethod(value, owner);
        }
    }
}